package API.Collection.Set.AboutHashCode;

public class Test {
    public static void main(String[] args) {
        // 未重写hashCode方法
        NoRewriteHashCode noRewriteHashCode1 = new NoRewriteHashCode("Jack", 20);
        NoRewriteHashCode noRewriteHashCode2 = new NoRewriteHashCode("Jack", 20);
        // 重写hashCode方法
        RewriteHashCode rewriteHashCode1 = new RewriteHashCode("Jack", 20);
        RewriteHashCode rewriteHashCode2 = new RewriteHashCode("Jack", 20);
        // 应为false，因为object底层的hashCode以地址为参数
        System.out.println(noRewriteHashCode1.hashCode() == noRewriteHashCode2.hashCode());
        // 应为true，因为hashCode被重写
        System.out.println(rewriteHashCode1.hashCode() == rewriteHashCode2.hashCode());
    }
}
